home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / xlisp21 / part01 next >
Encoding:
Text File  |  1990-02-26  |  53.1 KB  |  1,499 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Cognos Inc., Ottawa, Canada
  3. subject: v10i088: XLisP 2.1 sources 1a (1/3) / 5
  4. From: garym@cognos.UUCP (Gary Murphy)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 88
  8. Submitted-by: garym@cognos.UUCP (Gary Murphy)
  9. Archive-name: xlisp21/part01
  10.  
  11. Another attempt to get these sources to you: my first batch ran into 100k
  12. message limits, which means the message counts on any files you've received
  13. so far are not quite correct.
  14.  
  15. The whole kit should consist of 1a 1b 1c 2 3a 3b 4a 4b and 5 - I promise I'll
  16. be better at this next time :-)
  17.  
  18. [Ugh.  ++bsa]
  19.  
  20. I have included the sources as I downloaded them from MIPS BBS, with the
  21. collected bug-fixes/extensions &c appended as a collection of news
  22. articles.  This also includes the WINTERP and XLISP examples and tutorials
  23. recendly posted to comp.lang.lisp.x
  24. ------------------------------------------------------------------------
  25. #!/bin/sh
  26. # This is a shell archive, meaning:
  27. # 1. Remove everything above the #!/bin/sh line.
  28. # 2. Save the resulting text in a file.
  29. # 3. Execute the file with /bin/sh (not csh) to create the files:
  30. #    betz
  31. #    readme.1st
  32. #    readme.src
  33. #    winterp.doc
  34. #    xlisp.eg
  35. #    xlisp.ref
  36. #    xlisp.txt
  37. # This archive created: Sun Feb 18 23:27:40 1990
  38. # By:    Gary Murphy ()
  39. export PATH; PATH=/bin:$PATH
  40. echo shar: extracting "'betz'" '(1164 characters)'
  41. if test -f 'betz'
  42. then
  43.     echo shar: over-writing existing file "'betz'"
  44. fi
  45. sed 's/^X//' << \SHAR_EOF > 'betz'
  46. XFrom sce!mitel!uunet!samsung!brutus.cs.uiuc.edu!psuvax1!rutgers!cmcl2!dasys1!intern Fri Nov 24 09:01:48 EST 1989
  47. XArticle: 33 of comp.lang.lisp.x
  48. XPath: cognos!sce!mitel!uunet!samsung!brutus.cs.uiuc.edu!psuvax1!rutgers!cmcl2!dasys1!intern
  49. XFrom: intern@dasys1.UUCP (Steve Faiwiszewski)
  50. XNewsgroups: comp.lang.lisp.x
  51. XSubject: Re: Author! Author!
  52. XMessage-ID: <11273@dasys1.UUCP>
  53. XDate: 22 Nov 89 02:55:16 GMT
  54. XReferences: <1989Nov9.180124.24190@rpi.edu>
  55. XReply-To: intern@dasys1.UUCP (Steve Faiwiszewski)
  56. XOrganization: The Big Electric Cat
  57. XLines: 15
  58. X
  59. XIn article <1989Nov9.180124.24190@rpi.edu> jefu@pawl.rpi.edu (Jeffrey Putnam) writes:
  60. X>Does anyone have any suggestions for an email path to David Betz?  
  61. X>(I know this has been asked before, but news has this habit of expiring
  62. X>things...)
  63. X>
  64. X
  65. XDavid Betz' CompuServe id is 76704,47.  Last time I corresponded with him
  66. Xon CIS was about 6 months ago.  You can mail to him from the net by sending
  67. Xto 76704.47@compuserve.com
  68. X
  69. X    - Steve -
  70. X-- 
  71. X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  72. XSteve Faiwiszewski    bang   :  {sun!hoptoad , cmcl2!hombre} !dasys1!intern 
  73. X            domain : intern@dasys1.UUCP
  74. X
  75. X
  76. SHAR_EOF
  77. if test 1164 -ne "`wc -c 'betz'`"
  78. then
  79.     echo shar: error transmitting "'betz'" '(should have been 1164 characters)'
  80. fi
  81. echo shar: extracting "'readme.1st'" '(6702 characters)'
  82. if test -f 'readme.1st'
  83. then
  84.     echo shar: over-writing existing file "'readme.1st'"
  85. fi
  86. sed 's/^X//' << \SHAR_EOF > 'readme.1st'
  87. XThis is a list of new features in XLISP version 2.0 as of 15Nov87:
  88. X
  89. XSymbols have two value cells, one for normal values and one for
  90. Xfunction values.  SETQ sets the normal value, DEFUN sets the
  91. Xfunctional value.
  92. X
  93. XThe most important change from version 1.7 to 2.0 of XLISP is that
  94. Xit is now possible to save XLISP's workspace between sessions.  This
  95. Xfeature isn't necessarily part of every implementation of XLISP 2.0
  96. Xsince it is controlled by a compile-time conditional.  Check the file
  97. X'xlisp.h' to see if the symbol SAVERESTORE is defined for your machine
  98. Xbefore you try to use these functions.
  99. X
  100. XThe &key lambda list keyword is now supported as are initialization forms
  101. Xfor &optional, &key and &aux parameters.  The supplied-p variables are
  102. Xalso supported for &optional and &key parameters.
  103. X
  104. XNew functions and special forms:
  105. X
  106. X(save filename)        ; *** NOT IN ALL 2.0 IMPLEMENTATIONS ***
  107. X(restore filename)    ; *** NOT IN ALL 2.0 IMPLEMENTATIONS ***
  108. X(subseq string start [end])
  109. X(open name &key :direction)
  110. X(vector [expr]...)
  111. X(block name [expr]...)
  112. X(return-from name [value])
  113. X(tagbody [tag|expr]...)
  114. X(psetq [sym value]...)
  115. X(flet ([sym lambda-list [body]...]...) [expr]...)
  116. X(labels ([sym lambda-list [body]...]...) [expr]...)
  117. X(macrolet ([sym lambda-list [body]...]...) [expr]...)
  118. X(unwind-protect expr [expr]...)
  119. X(when test [expr]...)
  120. X(unless test [expr]...)
  121. X(loop [expr]...)
  122. X(progv symbols values [expr]...)
  123. X(pprint expr [stream])
  124. X(string< str1 str2 &key :start1 :end1 :start2 :end2)
  125. X(string= str1 str2 &key :start1 :end1 :start2 :end2)
  126. X(string> str1 str2 &key :start1 :end1 :start2 :end2)
  127. X(string<= str1 str2 &key :start1 :end1 :start2 :end2)
  128. X(string/= str1 str2 &key :start1 :end1 :start2 :end2)
  129. X(string>= str1 str2 &key :start1 :end1 :start2 :end2)
  130. X(string-lessp str1 str2 &key :start1 :end1 :start2 :end2)
  131. X(string-equal str1 str2 &key :start1 :end1 :start2 :end2)
  132. X(string-greaterp str1 str2 &key :start1 :end1 :start2 :end2)
  133. X(string-not-greaterp str1 str2 &key :start1 :end1 :start2 :end2)
  134. X(string-not-equal str1 str2 &key :start1 :end1 :start2 :end2)
  135. X(string-not-lessp str1 str2 &key :start1 :end1 :start2 :end2)
  136. X(string-trim bag string)
  137. X(string-left-trim bag string)
  138. X(string-right-trim bag string)
  139. X(string-upcase string &key :start :end)
  140. X(string-downcase string &key :start :end)
  141. X(nstring-upcase string &key :start :end)
  142. X(nstring-downcase string &key :start :end)
  143. X(symbol-function sym)
  144. X(send obj msg [expr]...)
  145. X(send-super msg [expr]...)
  146. X(integerp expr)
  147. X(floatp expr)
  148. X(stringp expr)
  149. X(arrayp expr)
  150. X(streamp expr)
  151. X(objectp expr)
  152. X(fboundp expr)
  153. X(characterp expr)
  154. X(int-char expr)
  155. X(char-int expr)
  156. X(read-byte [stream])
  157. X(write-byte expr [stream])
  158. X(make-string-input-stream string [start [end]])
  159. X(make-string-output-stream)
  160. X(get-output-stream-string stream)
  161. X(get-output-stream-list stream)
  162. X(get-lambda-expression closure)
  163. X(gcd expr1 expr2)
  164. X(macroexpand form)
  165. X(macroexpand-1 form)
  166. X
  167. XThere is now a real character data type.  All functions that are
  168. Xsupposed to return characters (like READ-CHAR) now do.
  169. X
  170. XThe reader is now capable of handling both single and multiple escapes.
  171. XThis means that it is possible to read the symbol |aBc| and get a symbol
  172. Xwith the print name "aBc".  The backslash can also be used as a single
  173. Xescape.  The same symbol could have been written \aB\c.
  174. X
  175. XThe read table now supports the character types :SESCAPE for single
  176. Xescape and :MESCAPE for multiple escapes.
  177. X
  178. XThe reader also supports the reader macros:
  179. X
  180. X    #:symbol    an uninterned symbol
  181. X    #| ... |#   a comment
  182. X    #Onumber    an octal number
  183. X    #Bnumber    a binary number
  184. X
  185. XThe following symbols preserve a history of values used by the
  186. Xread-eval-print loop:
  187. X
  188. X    -        the current input expression
  189. X    +        the last expression read
  190. X    ++        the previous value of +
  191. X    +++        the previous value of ++
  192. X    *        the result of the last evaluation
  193. X    **        the previous value of *
  194. X    ***        the previous value of **
  195. X
  196. XThe global symbol *PRINT-CASE* was added to control the output case of
  197. Xsymbols.  Its default value is :UPCASE which will cause symbols to
  198. Xbe printed in uppercase.  You can change it to :DOWNCASE to get symbols
  199. Xto print in lowercase.
  200. X
  201. XI have added the functions FIRST, SECOND, THIRD, FOURTH and REST as
  202. Xsynonyms for CAR, CADR, CADDR, CADDDR and CDR.
  203. X
  204. XChanged the default value of *print-case* to :upcase.
  205. X
  206. XAdded macros to init.lsp for:
  207. X
  208. X    (defvar sym &optional val)
  209. X    (defparameter sym val)
  210. X    (defconstant sym val)
  211. X
  212. XThese symbols control the format in which numbers are printed.  They
  213. Xshould be set to printf format strings.
  214. X
  215. X    *integer-format*    (default is "%d" or "%ld")
  216. X    *float-format*     (default is "%g")
  217. X
  218. X(substr string start [length]) is replaced by:
  219. X    (subseq string start [end])
  220. X
  221. X(openi name) is replaced by: (open name :direction :input)
  222. X(openo name) is replaced by: (open name :direction :output)
  223. X
  224. XOPEN, LOAD, SAVE and RESTORE take strings or symbols as file names.
  225. XIf a symbol is given, the print name of the symbol is used as the base
  226. Xfilename and the default extension (if any) is appended.
  227. X
  228. XRenamed MEM to ROOM and TRANSCRIPT to DRIBBLE.
  229. X
  230. XAdded a trace facility.  The evaluator will now print trace
  231. Xinformation for function and macro calls.  The names of the
  232. Xfunctions and macros to trace should be in a list that is stored
  233. Xas the value of *TRACELIST*.
  234. X
  235. XAdded macro definitions for TRACE and UNTRACE to "init.lsp".
  236. XTrace output goes to the stream that is the value of *TRACE-OUTPUT*.
  237. X
  238. XRemoved the hard wired prompting from READ.  There is no longer
  239. Xan unmatched left paren counter, but the debug level prompt remains.
  240. X
  241. XThe symbols *ERROR-OUTPUT* and *DEBUG-IO* have been added and
  242. Xare bound to streams that are used for error output and debug
  243. Xi/o respectively.
  244. X
  245. XThe symbol *GC-HOOK* has been added.  If it is bound to a function
  246. Xof two arguments, that function will be called after the garbage
  247. Xcollector runs.  The two parameters are the total number of nodes
  248. Xand the number free after the garbage collection.
  249. X
  250. XAdded the function (COMMAND-POINT-SIZE <n>) to the Macintosh version
  251. Xto set the point size for the text in the command window.  The default
  252. Xpoint size is 9.
  253. X
  254. XThe SEND-SUPER function replaces the :SENDSUPER message to objects.
  255. XAll messages must be sent using either the SEND function or the
  256. XSEND-SUPER function.  In other words, the syntax:
  257. X
  258. X    (Class :new '(a b c))
  259. X
  260. Xmust now be written as:
  261. X
  262. X    (send Class :new '(a b c))
  263. X
  264. Xand
  265. X
  266. X    (self :sendsuper :msg 1 2 3)
  267. X
  268. Xmust now be written as:
  269. X
  270. X    (send-super :msg 1 2 3)
  271. X
  272. XThis is because the CAR of a form is no longer evaluated.  To get the
  273. Xeffect of having the function position evaluated, use the FUNCALL form.
  274. X
  275. XThe syntax of LOAD has changed from:
  276. X
  277. X    (load name [verbose-flag [print-flag]])
  278. X
  279. Xto:
  280. X
  281. X    (load name &key :verbose :print)
  282. X
  283. X
  284. X
  285. SHAR_EOF
  286. if test 6702 -ne "`wc -c 'readme.1st'`"
  287. then
  288.     echo shar: error transmitting "'readme.1st'" '(should have been 6702 characters)'
  289. fi
  290. echo shar: extracting "'readme.src'" '(466 characters)'
  291. if test -f 'readme.src'
  292. then
  293.     echo shar: over-writing existing file "'readme.src'"
  294. fi
  295. sed 's/^X//' << \SHAR_EOF > 'readme.src'
  296. XThis archive contains the IBM-PC specific source code for XLISP
  297. Xversion 2.1.  In order to recompile XLISP, you'll also need the
  298. Xgeneric code archive.  These files were designed to be used with
  299. XTurbo C v2.0 and will probably need to be changed to use any other
  300. Xcompiler.  Before attempting to recompile any of the modules, make
  301. Xsure that the symbol _TURBOC_ is defined at the top of 'xlisp.h'
  302. Xwhere the machine type is specified (right under the copyright
  303. Xnotice).
  304. X
  305. X
  306. SHAR_EOF
  307. if test 466 -ne "`wc -c 'readme.src'`"
  308. then
  309.     echo shar: error transmitting "'readme.src'" '(should have been 466 characters)'
  310. fi
  311. echo shar: extracting "'winterp.doc'" '(14611 characters)'
  312. if test -f 'winterp.doc'
  313. then
  314.     echo shar: over-writing existing file "'winterp.doc'"
  315. fi
  316. sed 's/^X//' << \SHAR_EOF > 'winterp.doc'
  317. XFrom sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hplabsz!mayer Thu Jan 11 12:51:21 EST 1990
  318. XArticle: 2234 of comp.lang.lisp
  319. XPath: cognos!sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hplabsz!mayer
  320. XFrom: mayer@hplabsz.HPL.HP.COM (Niels Mayer)
  321. XNewsgroups: comp.lang.lisp
  322. XSubject: Re: XLISP Object Method Selectors :new and :isnew.
  323. XMessage-ID: <4613@hplabsz.HPL.HP.COM>
  324. XDate: 10 Jan 90 07:26:26 GMT
  325. XReferences: <1511@dinl.mmc.UUCP>
  326. XReply-To: mayer@hplabs.hp.com (Niels Mayer)
  327. XOrganization: Hewlett-Packard Labs, Software Technology Lab, Palo Alto, CA.
  328. XLines: 308
  329. XSummary:
  330. XExpires:
  331. XSender:
  332. XFollowup-To:
  333. X
  334. XIn article <1511@dinl.mmc.UUCP> noren@dinl.UUCP (Charles Noren) writes:
  335. X>It's been a while since I've been on the net.  I can no longer
  336. X>access comp.lang.lisp.x from our site, I suppose it went away?
  337. X
  338. Xit's still there...
  339. X
  340. X>I've just starting playing with XLISP v2.0, particularly the
  341. X>object-oriented features of it.  I've created new classes with
  342. X>instance and class variables, and I've used the :new selector
  343. X>to do so and it works just fine.  However, I see the :isnew
  344. X>selector in the documentation and I was wondering how that works
  345. X>compared to :new.
  346. X
  347. XWhen I first looked at XLISP, I too found the documentation on the
  348. Xobject system to be a little terse. Everything becomes much clearer
  349. Xonce you see some examples. 
  350. X
  351. XI recently wrote up some documentation on XLISP's object system for
  352. Xuse with WINTERP (an XLISP-based rapid prototyping environment for
  353. Xapplications based on the OSF Motif widgets). The following excerpt
  354. Xfrom winterp/doc/winterp.doc may help (get winterp via anonymous ftp
  355. Xfrom expo.lcs.mit.edu:oldcontrib/winterp.tar.Z). In particular, your
  356. Xquestion about :ISNEW is answered in the "object initialization"
  357. Xsection. 
  358. X
  359. X            --------------------
  360. X
  361. X* Introduction to XLISP objects and Widgets.
  362. X
  363. XWINTERP uses XLISP's object system as its interface to the class hierarchy
  364. Xof widgets provided by Motif. Specifically, each Motif widget class is
  365. Xrepresented by one or more object classes in WINTERP.  In order to best
  366. Xunderstand the capabilities of WINTERP's Motif interface, a brief review of
  367. Xthe XLISP object system is in order. You may also want to consult the XLISP
  368. Xdocumentation ./winterp/doc/xLisp.doc for a more precise definition of the
  369. Xobject system.
  370. X
  371. XXLISP Classes describe the type of a particular object by declaring a set
  372. Xof variables held in each object. These "instance variables" may only be
  373. Xaccessed by "methods" that respond to "messages" sent to the object.
  374. XMethods are defined for particular classes, and functionality of other
  375. Xclasses may be incorporated into new classes via "inheritance". From
  376. XXLISP, Motif widget classes look just like normal XLISP objects -- that
  377. Xmeans that you can easily extend the functionality of Motif widgets by
  378. Xadding your own methods to a particular widget class. You may also use
  379. Xinheritance to attach your own data structures to widgets. The result is
  380. Xthat WINTERP provides a very clean way to interactively rapid-prototype an
  381. Xapplication, while also providing mechanisms for code structuring and reuse.
  382. XThe latter is necessary in evolving from prototype to a structured,
  383. Xmaintainable, and customizable deliverable.
  384. X
  385. X
  386. X** Creating new objects.
  387. X
  388. XCreate a new instance of a class by sending the message :NEW to
  389. X<a_class_instance>:
  390. X
  391. X    (SEND <a_class_instance> :NEW <parameters>)
  392. X
  393. X<a_class_instance> is in fact an instance of class CLASS. Class CLASS allows
  394. Xyou to define new class instances by specifying the instance variables and
  395. Xparent class of a particular class.
  396. X
  397. X
  398. X** Declaring a class.
  399. X
  400. XTo declare a "base class" object, that is, an object with no parent object,
  401. Xjust send message :NEW to the object <CLASS>
  402. X
  403. X    (SEND CLASS :NEW '(<ivar0> ... <ivarN>)
  404. X             ['(<cvar0> ... <cvarM>)])
  405. X
  406. X'(<ivar0> ... (ivarN>) are a list of symbols. Each <ivar-i> names an
  407. Xinstance variable of the class. '(<cvar0> ... <cvarM>)]) are an optional
  408. Xlist of variables that are shared among all instances of that particular
  409. Xclass.
  410. X
  411. X
  412. X** Defining methods.
  413. X
  414. XWhen a "message" is sent to an object, XLISP searches for a "method" to
  415. Xanswer the message. A method is a piece of Lisp code that is executed when
  416. Xa particular message is sent to an object. Within the code of a method, all
  417. Xobject instance and class variables are accessible. Furthermore, the symbol
  418. X'self' is bound to the object the message was sent to.
  419. X
  420. XMethods are defined by sending the message :ANSWER to <a_class_instance>:
  421. X
  422. X    (SEND a_class_instance :ANSWER <:msg> <parameters> <code>)
  423. X
  424. Xwhere <:msg> is a keyword symbol (a symbol with a ':' prefix) representing
  425. Xthe message; <parameters> are the arguments given along with the message.
  426. XSee the documentation on "lambda lists" in /winterp/doc/xLisp.doc p.12 for
  427. Xdetails.  <code> is a list of s-expressions which get evaluated in response
  428. Xto a message. The lexical environment that existed for the call to :ANSWER
  429. Xwill be used for value and functional bindings during method evaluation.
  430. X
  431. XIf you need to remember what the syntax is, consider the memory-helper
  432. X    "this class :ANSWERs to :MESSAGE..." == (send <cls> :ANSWER :MESSAGE ...)
  433. X
  434. X
  435. X** Inheritance
  436. X
  437. XSo far, the object system we just described supports *encapsulation*.
  438. XEncapsulation is good programming practice because it helps localize and
  439. Xdetangle complexity. Unfortunately, encapsulation runs counter to
  440. Xflexibility because making flexible use of an object may require that
  441. Xcertain groups of instance variables be accessed by different layers of new
  442. Xfunctionality. Most often, one wants to *reuse* aspects of a particular
  443. Xclass in creating code that specializes and alters the functionality of
  444. Xthat class. A compromise between encapsulation and flexibility is found by
  445. Xusing *inheritance* in an object system. Inheritance is used to allow a
  446. X *subclass* to specialize the functionality of it's *parent class* (aka,
  447. Xthe *superclass*):
  448. X
  449. X    (send Class :NEW '(<ivar0> ... <ivarN>)
  450. X                         '(<cvar0> ... <cvarM>)
  451. X             <superclass>)
  452. X
  453. X(<ivar0> ... <ivarN>) is a list of new instance variables in the subclass;
  454. X(<cvar0> ... <cvarN>) is a list of new class variables in the subclass;
  455. X<superclass> is a class instance representing the parent from which
  456. Xthe new subclass inherits variables and methods.
  457. X
  458. X"Inheritance" is occurring because all the instance variables of all the
  459. Xparent classes of the new subclass become the variables of each subclass
  460. Xinstance. Furthermore, all methods defined on a parent class may also be
  461. Xused on a subclass instance. Note that while a subclass' methods can access
  462. Xthe variables defined on the parent classes, the reverse isn't true.
  463. X
  464. X
  465. X** Object initialization.
  466. X
  467. XAs mentioned earlier, new object instances are created by sending the
  468. Xmessage :NEW to a class object. Sending the message :NEW to a class
  469. Xautomatically sends message :ISNEW to the newly created instance. By
  470. Xdefault :ISNEW on an instance is a no-op method defined on class 'Object',
  471. Xwhich is the implicit [(grand)*]parent of all instances. If you want to
  472. Xinitialize the instance/class variables of a particular class, you must
  473. Xdefine an :ISNEW method on the class.  Any parameters originally sent to
  474. Xthe :NEW method will be passed on to the :ISNEW method and may be used to
  475. Xinitialize an object to outside-world parameters.
  476. X
  477. X
  478. X** Example of using OOP features of XLISP with Motif widgets:
  479. X
  480. XAs currently implemented, the Motif class xmListWidgetClass makes it a bit
  481. Xbaroque to create browsers (hopefully this will change in Motif 1.1).  The
  482. Xproblem is that a "browser" is a kind of application that lends itself to
  483. Xobject oriented techniques that are not always straightforward to support
  484. Xin C. One often has a collection of 'things' that one wants to display in a
  485. X'list' and perform actions on the 'thing' corresponding to the visual
  486. Xselection of an element in the displayed list. xmListWidgetClass will
  487. Xdisplay an arrray of XmStrings in a list. When one or more elements in the
  488. Xlist are selected, XmStrings corresponding to the selected elements are
  489. Xreturned. Since the XmStrings you put into the list widget are not the
  490. XXmStrings you get out, you must call XmStringCompare on each element of the
  491. Xcollection of 'things' to find out which ones are selected.  Presumably,
  492. Xyou'll want to do more than just get back an XmString...  normally one will
  493. Xwant to access data structures associated with the XmString so as to perform
  494. Xan action dependent on those structures. This could be done with a lookup
  495. Xtable, but there's also a better way...
  496. X
  497. XWINTERP allows us to subclass the Motif list widget so as to make it have
  498. Xthe kind of functionality we want. This subclass will contain an additional
  499. Xinstance variable 'items' which is an array of arbitrary XLISP objects to
  500. Xbe displayed in a textual browser made from the list widget. These objects
  501. Xcan have completely different internal representations -- the only
  502. Xrequirement is that they follow the protocol of being able to respond to
  503. Xthe messages :DISPLAY_STRING and :DEFAULT_ACTION. :DISPLAY_STRING returns a
  504. Xstring representation of the object to be displayed in the browser.
  505. X:DEFAULT_ACTION is the action to be performed when a list item is browsed
  506. X(by double clicking on the item).
  507. X
  508. XThe following creates the subclass <List_Browser> from superclass
  509. X<XM_LIST_WIDGET_CLASS>:
  510. X
  511. X    (setq List_Browser 
  512. X        (send Class :NEW        ;create a class inst
  513. X            '(items)        ;new instance vars
  514. X            '()            ;no class vars
  515. X            XM_LIST_WIDGET_CLASS))    ;superclass
  516. X
  517. XSo now all instances of <List_Browser> will contain an instance variable
  518. X<items> and will respond to all the messages understood by the
  519. XXM_LIST_WIDGET_CLASS. We want our list browser to behave as described
  520. Xabove, so we define an :ISNEW method to initialize instance variable
  521. X<items> to the list of arbitrary objects to be displayed.  <items> gets
  522. Xinitialized to an array of objects, the list widget is created, and a
  523. XXmNdefaultActionCallback is setup so that a double click will send the
  524. Xmessage :DEFAULT_ACTION to the browsed item:
  525. X
  526. X    ;; (send List_Browser :new <items_list> <args-for-the-list-widget>)
  527. X    ;; <items_list> is a list of BROWSER_OBJECTs as described above.
  528. X    ;; <args-for-the-list-widget> -- these are the arguments that
  529. X    ;;       will be passed on to the list widget
  530. X    ;;
  531. X    (send List_Browser :answer :isnew '(items_list &rest args)
  532. X          '(
  533. X        (let* (
  534. X               (items_end_idx (length items_list))
  535. X               (display_items (make-array items_end_idx)))
  536. X
  537. X          ;; initialize the 'items' instance variable so that it
  538. X          ;; holds all the BROWSER_OBJECTs passed in <items_list>
  539. X          (setq items (make-array items_end_idx)) ;create the array
  540. X          (do (                         ;copy elts from list to array
  541. X               (i    0          (1+ i))
  542. X               (elts items_list (cdr elts)))
  543. X              ;; loop till no more elts
  544. X              ((null elts))
  545. X              ;; loop body
  546. X              (setf (aref items i) (car elts))
  547. X              (setf (aref display_items i) 
  548. X                (send (car elts) :display_string))
  549. X              )
  550. X
  551. X          ;; initialize the widget, passing in the browser items.
  552. X          (apply 'send-super `(:isnew
  553. X                       ,@args
  554. X                       :xmn_selection_policy :browse_select
  555. X                       :xmn_items ,display_items
  556. X                       :xmn_item_count ,items_end_idx
  557. X                       ))
  558. X          )
  559. X
  560. X        ;; set up a callback on the list widget initialized above such
  561. X        ;; that a double click on the browser-item will send the
  562. X        ;; message :default_action to the BROWSER_OBJECT.
  563. X        (send-super :add_callback :xmn_default_action_callback
  564. X                '(callback_item_position)
  565. X                '((send (aref items (1- callback_item_position))
  566. X                    :default_action))
  567. X                )
  568. X        )
  569. X          )
  570. X
  571. X
  572. XIn the above code, SEND-SUPER works just like send, except that it doesn't
  573. Xrequire you to give it the object to send the message to.  Instead, it
  574. Ximplicitly assumes that it will be called from within a method, and will
  575. Xautomatically send the message to a superclass of the object's class.  The
  576. X(apply 'send-super ...) form is actually calling the :ISNEW (instance
  577. Xinitializer) method on XM_LIST_WIDGET_CLASS, which actually creates the
  578. Xwidget via XmCreateList() or XmCreateScrolledList(). The APPLY '`'
  579. X(BACKQUOTE) and '&rest args' (LAMBDA LIST) features of Lisp allow us to
  580. Xsplice in the argument list passed to the instance of List_Browser into the
  581. Xfunction that actually creates the widget. Finally, method :add_callback is
  582. Xthe WINTERP equivalent of XtAddCallback(). See the documentation on methods
  583. Xon WIDGET_CLASS for more details.
  584. X
  585. XThe Motif List widget also defines a number of "methods" implemented as C
  586. Xroutines such as XmListAddItem(), XmListAddItemUnselected(),
  587. XXmListDeleteItem(), and XmListDeletePos(). In WINTERP, we define these as
  588. Xmethods :ADD_ITEM, :ADD_ITEM_UNSELECTED, :DELETE_ITEM, and :DELETE_POS
  589. Xrespectively. Since these methods modify the collection of objects
  590. Xrepresented by the list widget, we must update the internal array of
  591. Xobjects <items> to correspond with the items displayed. We do this by
  592. Xintercepting those messages to the superclass of class <List_Browser> and
  593. Xhandle them in <List_Browser> so as to update the appropriate data:
  594. X
  595. X    (send List_Browser :answer :ADD_ITEM '(item position)
  596. X          '(
  597. X        (setq items (array-insert-pos items (1- position) item))
  598. X        (send-super :add_item 
  599. X                (send item :display_string) 
  600. X                position)
  601. X        )
  602. X          )
  603. X
  604. X    (send List_Browser :answer :ADD_ITEM_UNSELECTED '(item position)
  605. X          '(
  606. X        (setq items (array-insert-pos items (1- position) item))
  607. X        (send-super :add_item_unselected 
  608. X                (send item :display_string)
  609. X                position)
  610. X        )
  611. X          )
  612. X
  613. X    (send List_Browser :answer :DELETE_ITEM '(item)
  614. X          '(
  615. X        ;; this is too lame to implement... requires that we compare
  616. X        ;; item with the result of :display_string done on every elt
  617. X        ;; of ivar 'items'
  618. X        (error "Message :DELETE_ITEM not supported in List_Browser")
  619. X        )
  620. X          )
  621. X
  622. X    (send List_Browser :answer :DELETE_POS '(position)
  623. X          '(
  624. X        (setq items (array-delete-pos items (1- position)))
  625. X        (send-super :delete_pos position)
  626. X           )
  627. X         )
  628. X
  629. XTo see how this subclassed list browser is used, and also to see how one
  630. Xmight write a sample application in WINTERP using the object oriented
  631. Xfeatures of XLISP, see ./winterp/examples/grep-br.lsp.  That file
  632. Ximplements a simple search browser based on the UN*X command 'grep'. See
  633. Xalso ./winterp/examples/mail-br.lsp to see how you can build a simple
  634. Xmh-based mail browser. Finally, as another example of subclassing Motif
  635. Xwidgets, see ./winterp/examples/radiobox2.lsp.
  636. X-------------------------------------------------------------------------------
  637. X        Niels Mayer -- hplabs!mayer -- mayer@hplabs.hp.com
  638. X          Human-Computer Interaction Department
  639. X               Hewlett-Packard Laboratories
  640. X                  Palo Alto, CA.
  641. X                   *
  642. X
  643. X
  644. SHAR_EOF
  645. if test 14611 -ne "`wc -c 'winterp.doc'`"
  646. then
  647.     echo shar: error transmitting "'winterp.doc'" '(should have been 14611 characters)'
  648. fi
  649. echo shar: extracting "'xlisp.eg'" '(7724 characters)'
  650. if test -f 'xlisp.eg'
  651. then
  652.     echo shar: over-writing existing file "'xlisp.eg'"
  653. fi
  654. sed 's/^X//' << \SHAR_EOF > 'xlisp.eg'
  655. XFrom sce!mitel!uunet!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Fri Feb 16 07:17:21 EST 1990
  656. XArticle: 73 of comp.lang.lisp.x
  657. XPath: cognos!sce!mitel!uunet!mailrus!cs.utexas.edu!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
  658. XFrom: tim@hpfcbig.SDE.HP.COM (Tim Mikkelsen)
  659. XNewsgroups: comp.lang.lisp.x
  660. XSubject: Re: intro to XLISP objects
  661. XMessage-ID: <1170006@hpfcbig.SDE.HP.COM>
  662. XDate: 12 Feb 90 16:24:20 GMT
  663. XReferences: <1170004@hpfcbig.SDE.HP.COM>
  664. XOrganization: HP SESD, Fort Collins, CO
  665. XLines: 228
  666. X
  667. X
  668. XA MORE REALISTIC EXAMPLE 
  669. X______________________________________________________________________________
  670. X
  671. X
  672. XThe following is an example, using the idea of tools again.  It contains
  673. Xa hierarchy of tool  classes.  The top of the class  hierarchy is TOOLS.
  674. XHAND-TOOLS and SHOP-TOOLS are sub-classes of TOOLS.  The example creates
  675. Xinstances of these  sub-classes.  It is possible to extend this  example
  676. Xin various ways.  One obvious  extension would be to create a third tier
  677. Xof classes  under  HAND-TOOLS  that could  contain  classes like drills,
  678. Xscrewdrivers, pliers and so on.
  679. X
  680. X
  681. X
  682. X
  683. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  684. X;
  685. X;    File name:    tools.lsp
  686. X;    Author:        Tim Mikkelsen
  687. X;    Description:    Object-oriented example program
  688. X;    Language:    XLISP 2.0
  689. X;
  690. X;    Date Created:    10-Jan-1988
  691. X;    Date Updated:    2-Apr-1989
  692. X;    
  693. X;    (c) Copyright 1988, by Tim Mikkelsen, all rights reserved.
  694. X;        Permission is granted for unrestricted non-commercial use.
  695. X;
  696. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  697. X
  698. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  699. X;
  700. X;    Define the superclasses and classes
  701. X;
  702. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  703. X
  704. X;
  705. X; make TOOLS superclass
  706. X;    with a different :ISNEW method
  707. X;    added methods are :BORROW and :RETURN
  708. X;    class variables are    NUMBER        contains # of tool instances
  709. X;                ACTIVE-LIST    contains list of current objects
  710. X;    instance variables are     POWER         list - (AC BATTERY HAND)
  711. X;                MOVEABLE     CAN-CARRY or CAN-ROLL or FIXED
  712. X;                OPERATIONS    list
  713. X;                MATERIAL     list - (WOOD METAL PLASTIC ...)
  714. X;                PIECES         list
  715. X;                LOCATION    HOME or person's name
  716. X;
  717. X
  718. X(setq tools (send class :new '(power 
  719. X                   moveable 
  720. X                   operations 
  721. X                   material 
  722. X                   pieces 
  723. X                   location) 
  724. X                 '(number active-list)))
  725. X(send tools :answer :isnew '() 
  726. X                   '((if (null number) (setq number 1)
  727. X                                 (setq number (1+ number)))
  728. X                 (setq active-list (cons self active-list))
  729. X                 (setq location 'home)))
  730. X(send tools :answer :borrow '(by-who)
  731. X                    '((if (eq location 'home) (setq location by-who)
  732. X                                     (print "you can't"))))
  733. X(send tools :answer :return '()
  734. X                    '((if (eq location 'home) (print "got it already")
  735. X                                     (setq location 'home))))
  736. X
  737. X;
  738. X; make HAND-TOOLS class
  739. X;    with a different :ISNEW method
  740. X;    new instance variable    WEIGHT        <number> of pounds
  741. X;    the rest is inherited from TOOLS 
  742. X; 
  743. X
  744. X(setq hand-tools (send class :new '(weight) '() tools))
  745. X(send hand-tools :answer :isnew '(pow op mat parts w-in)
  746. X                    '((setq power pow)
  747. X                      (setq moveable 'can-carry)
  748. X                      (setq operations op)
  749. X                      (setq material mat)
  750. X                          (setq pieces parts)
  751. X                      (setq weight w-in)
  752. X                      (send-super :isnew)))
  753. X
  754. X;
  755. X; make SHOP-TOOLS class
  756. X;    with a different :ISNEW method
  757. X;    no new instance variables
  758. X;    the rest is inherited from TOOLS 
  759. X; 
  760. X
  761. X(setq shop-tools (send class :new '() '() tools))
  762. X(send shop-tools :answer :isnew '(pow mov op mat parts)
  763. X                    '((setq power pow)
  764. X                     (setq moveable mov)
  765. X                     (setq operations op)
  766. X                     (setq material mat)
  767. X                     (setq pieces parts)
  768. X                     (send-super :isnew)))
  769. X
  770. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  771. X;
  772. X;    Create instances of various tool classes 
  773. X;
  774. X;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  775. X
  776. X(setq hand-drill (send hand-tools :new         ; make an instance - HAND-DRILL
  777. X                 '(ac) 
  778. X                 '(drill polish grind screw)
  779. X                 '(wood metal plastic)
  780. X                 '(drill drill-bits screw-bits buffer)
  781. X                 '2.5))
  782. X
  783. X(setq table-saw (send shop-tools :new         ; make an instance - TABLE-SAW
  784. X                 '(ac)
  785. X                 'fixed
  786. X                 '(rip cross-cut)
  787. X                 '(wood plastic)
  788. X                 '(saw blades fence)))
  789. X
  790. X
  791. X(setq radial-arm (send shop-tools :new         ; make an instance = RADIAL-ARM
  792. X                 '(ac)
  793. X                 'can-roll
  794. X                 '(rip cross-cut)
  795. X                 '(wood plastic)
  796. X                 '(saw blades dust-bag)))
  797. X
  798. X
  799. XThe following  session shows how to use the tool  definitions  from this
  800. Xbetter  example.  The example starts at the OS shell and brings up xlisp
  801. Xrunning the file 'tools.lsp'.
  802. X
  803. X     ________________________________________________________________
  804. X    |
  805. X    |    cmd? xlisp tools
  806. X    |    ; loading "init.lsp"
  807. X    |    ; loading "tools.lsp"
  808. X    |    > (send hand-drill :borrow 'fred)
  809. X    |    FRED
  810. X    |
  811. X    |    > (send table-saw :return)
  812. X    |    "got it already"
  813. X    |    "got it already"
  814. X    |
  815. X    |    > (send hand-drill :borrow 'joe)
  816. X    |    "you can't"
  817. X    |    "you can't"
  818. X    |
  819. X    |    > (send hand-drill :return)
  820. X    |    HOME
  821. X    |________________________________________________________________
  822. X
  823. X
  824. XSo, Fred was able to borrow the HAND-DRILL.  When an attempt was made to
  825. Xreturn the  TABLE-SAW,  it was  already  at home.  A second  attempt  to
  826. Xborrow the HAND-DRILL  indicated that "you can't" because it was already
  827. Xlent out.  Lastly, the HAND-DRILL was returned successfully.  (Note that
  828. Xthe "got it  already"  and "you  can't"  strings  show up  twice  in the
  829. Xdisplay because the methods both print and return the string.)
  830. X
  831. XThe following session shows the structure of the TOOLS object:
  832. X
  833. X     ________________________________________________________________
  834. X    |
  835. X    |    > (send tools :show)
  836. X    |    Object is #<Object: #276fc>, Class is #<Object: #23fe2>
  837. X    |      MESSAGES = ((:RETURN . #<Closure-:RETURN: #2dbd0>) 
  838. X    |                (:BORROW . #<Closure-:BORROW: #2ddba>) 
  839. X    |              (:ISNEW . #<Closure-:ISNEW: #274a4>))
  840. X    |      IVARS = (POWER MOVEABLE OPERATIONS MATERIAL PIECES LOCATION)
  841. X    |      CVARS = (NUMBER ACTIVE-LIST)
  842. X    |      CVALS = #(3 (#<Object: #2cadc> 
  843. X    |                 #<Object: #2cda2> 
  844. X    |           #<Object: #2d0e0>))
  845. X    |      SUPERCLASS = #<Object: #23fd8>
  846. X    |      IVARCNT = 6
  847. X    |      IVARTOTAL = 6
  848. X    |    #<Object: #276fc>
  849. X    |________________________________________________________________
  850. X
  851. X
  852. XThe two TOOLS sub-classes HAND-TOOLS and SHOP-TOOLS structure looks like:
  853. X
  854. X     ________________________________________________________________
  855. X    |
  856. X    |    > (send hand-tools :show)
  857. X    |    Object is #<Object: #2dab8>, Class is #<Object: #23fe2>
  858. X    |      MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d7a2>))
  859. X    |      IVARS = (WEIGHT)
  860. X    |      CVARS = NIL
  861. X    |      CVALS = NIL
  862. X    |      SUPERCLASS = #<Object: #276fc>
  863. X    |      IVARCNT = 1
  864. X    |      IVARTOTAL = 7
  865. X    |    #<Object: #2dab8>
  866. X    |
  867. X    |    > (send shop-tools :show)
  868. X    |    Object is #<Object: #2d680>, Class is #<Object: #23fe2>
  869. X    |      MESSAGES = ((:ISNEW . #<Closure-:ISNEW: #2d450>))
  870. X    |      IVARS = NIL
  871. X    |      CVARS = NIL
  872. X    |      CVALS = NIL
  873. X    |      SUPERCLASS = #<Object: #276fc>
  874. X    |      IVARCNT = 0
  875. X    |      IVARTOTAL = 6
  876. X    |    #<Object: #2d680>
  877. X    |________________________________________________________________
  878. X
  879. X
  880. XThe class HAND-TOOLS has an instance HAND-DRILL which looks like:
  881. X
  882. X     ________________________________________________________________
  883. X    |
  884. X    |    > (send hand-drill :show)
  885. X    |    Object is #<Object: #2d0e0>, Class is #<Object: #2dab8>
  886. X    |      WEIGHT = 2.5
  887. X    |      POWER = (AC)
  888. X    |      MOVEABLE = CAN-CARRY
  889. X    |      OPERATIONS = (DRILL POLISH GRIND SCREW)
  890. X    |      MATERIAL = (WOOD METAL PLASTIC)
  891. X    |      PIECES = (DRILL DRILL-BITS SCREW-BITS BUFFER)
  892. X    |      LOCATION = HOME
  893. X    |    #<Object: #2d0e0>
  894. X    |________________________________________________________________
  895. X
  896. X
  897. SHAR_EOF
  898. if test 7724 -ne "`wc -c 'xlisp.eg'`"
  899. then
  900.     echo shar: error transmitting "'xlisp.eg'" '(should have been 7724 characters)'
  901. fi
  902. echo shar: extracting "'xlisp.ref'" '(3263 characters)'
  903. if test -f 'xlisp.ref'
  904. then
  905.     echo shar: over-writing existing file "'xlisp.ref'"
  906. fi
  907. sed 's/^X//' << \SHAR_EOF > 'xlisp.ref'
  908. XFrom sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Mon Jan  8 09:06:27 EST 1990
  909. XArticle: 2222 of comp.lang.lisp
  910. XPath: cognos!sce!mitel!uunet!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
  911. XFrom: tim@hpfcbig.SDE.HP.COM (Tim Mikkelsen)
  912. XNewsgroups: comp.lang.lisp
  913. XSubject: Re: XLISP 2.0 reference available
  914. XMessage-ID: <6950018@hpfcbig.SDE.HP.COM>
  915. XDate: 6 Jan 90 04:33:30 GMT
  916. XReferences: <6950014@hpfcbig.SDE.HP.COM>
  917. XOrganization: HP SESD, Fort Collins, CO
  918. XLines: 19
  919. X
  920. XAn accessable ftp machine!
  921. X
  922. XThe XLISP 2.0 reference  has been made  available  for  anonymous FTP on
  923. Xhost cs.orst.edu, in the pub/xlisp directory, file xlispref.txt (a plain
  924. XASCII  text  file,  roughly  412k in  size).  It is  requested  that you
  925. Xretrieve  this  file  ONLY  during  non-working  hours  (say 7pm to 7am,
  926. XPacific Time).
  927. X
  928. XI've tested access to this machine and the file and I was able to get at
  929. Xit.  As  mentioned  the file is large, so it took about 9 minutes to get
  930. Xthe entire file at 8 PM.
  931. X
  932. X
  933. XThanks to Marion Hakanson (hakanson@cse.ogi.edu) for getting this put on
  934. Xcs.orst.edu.  There will be a few other machines that the reference will
  935. Xbe ftp'able from (including  simtel20).  I'll post these new machines on
  936. Xcomp.lang.lisp.x (which is probably where this note should have gone).
  937. X
  938. XTim Mikkelsen
  939. X
  940. X
  941. XFrom sce!mitel!uunet!visdc!jiii Mon Jan  8 09:06:33 EST 1990
  942. XArticle: 2223 of comp.lang.lisp
  943. XPath: cognos!sce!mitel!uunet!visdc!jiii
  944. XFrom: jiii@visdc.UUCP (John E Van Deusen III)
  945. XNewsgroups: comp.lang.lisp
  946. XSubject: Re: XLISP 2.0 reference available
  947. XSummary: sed script for reformatting
  948. XMessage-ID: <726@visdc.UUCP>
  949. XDate: 6 Jan 90 19:58:28 GMT
  950. XReferences: <6950014@hpfcbig.SDE.HP.COM> <6950017@hpfcbig.SDE.HP.COM>
  951. XReply-To: jiii@visdc.UUCP (John E Van Deusen III)
  952. XOrganization: VI Software Development, Boise, Idaho
  953. XLines: 70
  954. X
  955. XTo everyone who has obtained Tim Mikkelsen's excellent and very
  956. Xuseful XLISP Reference in ASCII format, the following sed script
  957. Xmight be of interest to you.  It slightly reformats the document
  958. Xso that when piped through pr(1), there are no empty pages.  It
  959. Xalso keeps the text within reasonable margins for printing on
  960. X8.5x11" paper, and provides some additional consistency in tabbing
  961. Xand line spacing.
  962. X
  963. XAssuming that you have the files ref1.Z, ref2.Z, ref3.Z, ref4.Z,
  964. Xand ref5.Z as provided by Tim Mikkelsen, and the sed script
  965. Xcontained here has been saved as sedf; the following command, or a
  966. Xvariation, will produce the reformatted document in the file prt:
  967. X
  968. X$ zcat ref[1-5].Z | sed -f sedf | pr -h "XLISP Reference" > prt
  969. X
  970. X--
  971. XJohn E Van Deusen III, PO Box 9283, Boise, ID  83707, (208) 343-1865
  972. X
  973. Xuunet!visdc!jiii
  974. X
  975. X===cut here===
  976. X/^[ ]$/,${
  977. X    s/^[    ]        /        /
  978. X    s/^        /    /
  979. X    s/^ [    ]/    /
  980. X    /^ /s/^ */    /
  981. X    /^[    ][    ]*  [    ][    ]*/s/  //
  982. X    /^EXAMPLES$/,/^[^    ]/{
  983. X        /^[     ]*$/d
  984. X        /^    /!{
  985. X            /^EXAMPLES$/a\
  986. X
  987. X            /^EXAMPLES$/!{
  988. X                /^[ ]/!i\
  989. X
  990. X            }
  991. X
  992. X        }
  993. X        s/^    //
  994. X    }
  995. X    /^SYNTAX$/,/^DESCRIPTION$/{
  996. X        /^[    ][    ]*<.*>.*-/,/^$/{
  997. X            s/- *[    ]/- /
  998. X            />.*- /!{
  999. X                /^[    ][    ]* /!{
  1000. X                    s/^[    ][    ]*/&  /
  1001. X                }
  1002. X                s/^    //
  1003. X            }
  1004. X        }
  1005. X    }
  1006. X    /^DESCRIPTION$/,/^EXAMPLES$/{
  1007. X        s/  */ /g
  1008. X        s/\. /\.  /g
  1009. X    }
  1010. X    /^[A-Z][A-Z ]*:/,/^$/{
  1011. X        s/  */ /g
  1012. X        s/\. /\.  /g
  1013. X    }
  1014. X    /^$/,/^..*/{
  1015. X        /^$/d
  1016. X        /^[ ]$/!i\
  1017. X
  1018. X    }
  1019. X    /^[ ]$/,/^.*/{
  1020. X        /^[ ]$/d
  1021. X        /^$/d
  1022. X        /^.*$/s/^.*$/ &/
  1023. X    }
  1024. X}
  1025. X
  1026. X
  1027. SHAR_EOF
  1028. if test 3263 -ne "`wc -c 'xlisp.ref'`"
  1029. then
  1030.     echo shar: error transmitting "'xlisp.ref'" '(should have been 3263 characters)'
  1031. fi
  1032. echo shar: extracting "'xlisp.txt'" '(15230 characters)'
  1033. if test -f 'xlisp.txt'
  1034. then
  1035.     echo shar: over-writing existing file "'xlisp.txt'"
  1036. fi
  1037. sed 's/^X//' << \SHAR_EOF > 'xlisp.txt'
  1038. XFrom sce!mitel!uunet!snorkelwacker!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim Fri Feb 16 07:18:45 EST 1990
  1039. XArticle: 74 of comp.lang.lisp.x
  1040. XPath: cognos!sce!mitel!uunet!snorkelwacker!tut.cis.ohio-state.edu!ucbvax!hplabs!hpfcso!hpfcbig!tim
  1041. XFrom: tim@hpfcbig.SDE.HP.COM (Tim Mikkelsen)
  1042. XNewsgroups: comp.lang.lisp.x
  1043. XSubject: Re: intro to XLISP objects
  1044. XMessage-ID: <1170005@hpfcbig.SDE.HP.COM>
  1045. XDate: 12 Feb 90 16:23:48 GMT
  1046. XReferences: <1170004@hpfcbig.SDE.HP.COM>
  1047. XOrganization: HP SESD, Fort Collins, CO
  1048. XLines: 434
  1049. X
  1050. X
  1051. X
  1052. X
  1053. X
  1054. X
  1055. X
  1056. X
  1057. X
  1058. X
  1059. X
  1060. X
  1061. X               XLISP 2.0 OBJECTS PRIMER
  1062. X
  1063. X
  1064. X                     by 
  1065. X
  1066. X                   Tim I Mikkelsen
  1067. X
  1068. X
  1069. X                  February 3, 1990
  1070. X
  1071. X
  1072. X
  1073. X
  1074. X
  1075. X
  1076. X
  1077. X
  1078. X    Copyright  (c) 1990 by Tim I.  Mikkelsen.  All Rights  Reserved.
  1079. X    No part of this document may be copied, reproduced or translated
  1080. X    for commercial use without prior written  consent of the author.
  1081. X    Permission  is granted  for  non-commercial  use as long as this
  1082. X    notice is left intact.
  1083. X
  1084. X
  1085. X    ________________________________________________________________
  1086. X
  1087. X    
  1088. X    One of the  features  in the design of XLISP is  object-oriented
  1089. X    programming.  This  primer is  intended to serve as a very brief
  1090. X    introduction  to the object  facilities of the XLISP 2.0 dialect
  1091. X    of LISP.  Note that the object  features  of XLISP are not based
  1092. X    on other existing object definitions in other LISP dialects.  If
  1093. X    you find problems in the primer, I'd appreciate hearing.
  1094. X
  1095. X
  1096. X            Tim Mikkelsen
  1097. X            4316 Picadilly Drive
  1098. X            Fort Collins, Colorado  80526
  1099. X
  1100. X
  1101. X
  1102. XPROGRAMMING STYLES
  1103. X______________________________________________________________________________
  1104. X
  1105. X
  1106. XThere are many  programming  paradigms  (models).  Some of the paradigms
  1107. Xare procedural, functional, rule-based, declarative and object-oriented.
  1108. XA language can have aspects of one or many of these programming  models.
  1109. X
  1110. X
  1111. XProcedure-Oriented
  1112. X
  1113. XThe programming paradigm most people are familiar with is the procedural
  1114. Xstyle.  The primitives in procedural  programming  are:  subroutines and
  1115. Xdata  structures.  Through  these  primitives,   programmers  have  some
  1116. Xlimited abilities to share programs and program fragments.  C and Pascal
  1117. Xare examples of procedural  languages.  Some procedural  languages (such
  1118. Xas Modula and ADA) have  extensions  that provide for better  sharing of
  1119. Xcode.
  1120. X
  1121. X
  1122. XObject-Oriented Programming
  1123. X
  1124. XObject-oriented  programming  is based  on the  primitives  of  objects,
  1125. Xclasses and messages.  Objects are defined in terms of classes.  Actions
  1126. Xoccur by sending a message to an object.  An object's  definition can be
  1127. Xinherited  from  more  general  classes.  Objective-C  and C++ both  are
  1128. Xobject-oriented  dialects of the C language.  Many dialects of LISP have
  1129. Xsome object oriented extension (Flavors, Common LOOPS, CLOS and others).
  1130. XThere  currently is standards  work  proceeding  to add  object-oriented
  1131. Xprogramming to Common LISP.
  1132. X
  1133. X
  1134. XObject Oriented Programming
  1135. X
  1136. XSo, the  object-oriented  programming model is based around the concepts
  1137. Xof objects,  classes and messages.  An object is essentially a black box
  1138. Xthat contains internal state  information.  You send an object a message
  1139. Xwhich causes the object to perform some  operation.  Objects are defined
  1140. Xand described through classes.
  1141. X
  1142. XOne aspect of an object is that you do not have to know what is inside -
  1143. Xor how it  works - to be able to use it.  From a  programming  point  of
  1144. Xview,  this is very  handy.  You can  develop a series  of  objects  for
  1145. Xsomeone to use.  If you need to change what goes on inside, the users of
  1146. Xthe objects should be unaware.
  1147. X
  1148. XAnother aspect of objects is that of  inheritance.  You can build up new
  1149. Xclasses  from  existing  classes  by  inheriting  the  existing  class's
  1150. Xfunctionality  and then extending the new  definition.  For example, you
  1151. Xcan  define a tool class  (with  various  attributes)  and then go about
  1152. Xcreating  object  instances  tool-1,  tool-2,  and so on.  You can  also
  1153. Xcreate new sub-classes of the tool class like  power-tool.  This is also
  1154. Xvery handy because you don't have to  re-implement  something if you can
  1155. Xbuild it up from existing code.
  1156. X
  1157. X
  1158. X
  1159. X
  1160. XXLISP OBJECT-ORIENTED PROGRAMMING
  1161. X______________________________________________________________________________
  1162. X
  1163. X
  1164. X
  1165. XXLISP OBJECT TERMINOLOGY
  1166. X
  1167. XThere  are, as  previously  mentioned,  many  different  languages  with
  1168. Xobject-oriented  extensions and facilities.  The terminology, operations
  1169. Xand  styles of these are very  different.  Some of the main  definitions
  1170. Xfor XLISP's object-oriented extensions are:
  1171. X
  1172. X    Object data type        The OBJECT DATA TYPE is a built-in  data
  1173. X                type of  XLISP.  Members  of the  object
  1174. X                data  type  are  object   instances  and
  1175. X                classes.
  1176. X
  1177. X    Object instances        An  OBJECT   INSTANCE  is  a   composite
  1178. X                structure that contains  internal  state
  1179. X                information,  methods  (the  code  which
  1180. X                respond to  messages),  a pointer to the
  1181. X                object  instance's  defining class and a
  1182. X                pointer  to  the  object's  super-class.
  1183. X                XLISP   contains   no  built-in   object
  1184. X                instances.
  1185. X
  1186. X    Class objects           A  CLASS  OBJECT  is,  essentially,  the
  1187. X                template for defining the derived object
  1188. X                instances.  A  class  object,   although
  1189. X                used  differently  from a simple  object
  1190. X                instance,  is  structurally  a member of
  1191. X                the  object   data   type.  It  is  also
  1192. X                contains  the  linking   mechanism  that
  1193. X                allows  you to build  class  hierarchies
  1194. X                (sub-classes and  super-classes).  XLISP
  1195. X                contains  two  built-in  class  objects:
  1196. X                OBJECT and CLASS.
  1197. X
  1198. X    Message selector        The MESSAGE  SELECTOR is the symbol that
  1199. X                is used to  select a  particular  action
  1200. X                (Method) from the object.
  1201. X
  1202. X    Message                 The  MESSAGE is the  combination  of the
  1203. X                message  selector  and the data (if any)
  1204. X                to be sent to the object.
  1205. X
  1206. X    Method                  The METHOD is the actual  code that gets
  1207. X                executed  when the object  receives  the
  1208. X                Message.
  1209. X
  1210. X
  1211. X
  1212. XSENDING MESSAGES
  1213. X
  1214. XThe  mechanism  for  sending  messages to XLISP  objects is via the SEND
  1215. Xfunction.  It takes an object, a message  selector and various  optional
  1216. Xarguments (depending on the message selector).
  1217. X
  1218. XThe way that a user  creates a new object is to send a :NEW message to a
  1219. Xpreviously  defined  class.  The  result  of this  SEND will  return  an
  1220. Xobject, so this is normally preceded by a SETQ.  The values shown in the
  1221. Xexamples  that follow may not match what you see if you try this on your
  1222. Xversion of XLISP - this is not an error.  The  screens  that are used in
  1223. Xthe various examples are similar to what you should see on your computer
  1224. Xscreen.  The ">" is the normal XLISP prompt (the  characters that follow
  1225. Xthe prompt is what you should type in to try these examples).
  1226. X
  1227. X
  1228. X     ________________________________________________________________
  1229. X    |
  1230. X    |    > (setq my-object (send object :new))
  1231. X    |    #<Object: #2e100>
  1232. X    |________________________________________________________________
  1233. X
  1234. X
  1235. XThe object  created here is of limited  value.  Most often, you create a
  1236. Xclass  object and then you create  instances  of that  class.  So in the
  1237. Xfollowing  example, a class called MY-CLASS is created that inherits its
  1238. Xdefinition from the a built-in CLASS definition.  Then two instances are
  1239. Xcreated of the new class.
  1240. X
  1241. X     ________________________________________________________________
  1242. X    |
  1243. X    |    > (setq my-class (send class :new '()))
  1244. X    |    #<Object: #27756>
  1245. X    |    
  1246. X    |    > (setq my-instance (send my-class :new))
  1247. X    |    #<Object: #27652>
  1248. X    |
  1249. X    |    > (setq another-instance (send my-class :new))
  1250. X    |#<Object: #275da>
  1251. X    |________________________________________________________________
  1252. X
  1253. X
  1254. X
  1255. XCLASSES
  1256. X
  1257. XPreviously,  a :NEW  message was used to create an object.  The  message
  1258. Xused to see what is in an object is the :SHOW message.
  1259. X
  1260. X     ________________________________________________________________
  1261. X    |
  1262. X    |    > (send my-class :show)
  1263. X    |    Object is #<Object: #27756>, Class is #<Object: #23fe2>
  1264. X    |      MESSAGES = NIL
  1265. X    |      IVARS = NIL
  1266. X    |      CVARS = NIL
  1267. X    |      CVALS = NIL
  1268. X    |      SUPERCLASS = #<Object: #23fd8>
  1269. X    |      IVARCNT = 0
  1270. X    |      IVARTOTAL = 0
  1271. X    |    #<Object: #27756>
  1272. X    |________________________________________________________________
  1273. X
  1274. X
  1275. XFrom the display of the MY-CLASS  object you can see there are a variety
  1276. Xof components.  The components of a class are:
  1277. X
  1278. X    Class Pointer           This  pointer  shows to what  class  the
  1279. X                object (instance or class) belongs.  For
  1280. X                a  class,  this  always  points  to  the
  1281. X                built-in  object  CLASS.  This  is  also
  1282. X                true  of the  CLASS  object,  its  class
  1283. X                pointer points to itself.
  1284. X
  1285. X    Superclass Pointer      This  pointer  shows what the next class
  1286. X                up the class  hierarchy is.  If the user
  1287. X                does  not  specify  what  class  is  the
  1288. X                superclass,   it  will   point   to  the
  1289. X                built-in class OBJECT.
  1290. X
  1291. X    Messages                This  component  shows what messages are
  1292. X                allowed   for   the   class,   and   the
  1293. X                description  of the method  that will be
  1294. X                used.  If the method is  system-defined,
  1295. X                it will show up in the form of '#<Subr-:
  1296. X                #18b98>'.  Remember   that   the   class
  1297. X                hierarchy    (through   the   Superclass
  1298. X                Pointer) is  searched  if the  requested
  1299. X                message is not found in the class.
  1300. X
  1301. X    Instance Variables      This   component   lists  what  instance
  1302. X                variables will be created when an object
  1303. X                instance is created.  If no instances of
  1304. X                the class  exist,  there are no Instance
  1305. X                Variables.  If there are 5 instances  of
  1306. X                a  class,  there  are  5  complete   and
  1307. X                different   groups   of   the   Instance
  1308. X                Variables.
  1309. X
  1310. X    Class Variables         The  CLASS  VARIABLES  (CVAR)  component
  1311. X    and Values        lists what class variables  exist within
  1312. X                the  class.  The  Class  Values   (CVAL)
  1313. X                component  shows what the current values
  1314. X                of the variables  are.  Class  Variables
  1315. X                are used to hold state information about
  1316. X                a class.  There  will be |Bone of each|A
  1317. X                of the Class  Variables,  independent of
  1318. X                the  number of  instances  of the  class
  1319. X                created.
  1320. X
  1321. XA BETTER EXAMPLE
  1322. X
  1323. XThe  example  previously  shown  does work, but the class and  instances
  1324. Xcreated  don't really do anything of  interest.  The  following  example
  1325. Xsets up a tool class and creates some tool instances.
  1326. X
  1327. X     ________________________________________________________________
  1328. X    |
  1329. X    |    > (setq my-tools (send class :new '(power moveable operation)))
  1330. X    |    #<Object: #277a6>
  1331. X    |
  1332. X    |    > (send my-tools :answer :isnew '(pow mov op) 
  1333. X    |                     '((setq power pow)
  1334. X    |                       (setq moveable mov)
  1335. X    |                       (setq operation op)))
  1336. X    |    #<Object: #277a6>
  1337. X    |
  1338. X    |    > (setq drill (send my-tools :new 'AC t 'holes))
  1339. X    |    #<Object: #2ddbc>
  1340. X    |
  1341. X    |    > (setq hand-saw (send my-tools :new 'none t 'cuts))
  1342. X    |    #<Object: #2dc40>
  1343. X    |
  1344. X    |    > (setq table-saw (send my-tools :new 'AC nil 'cuts))
  1345. X    |    #<Object: #2db00>
  1346. X    |________________________________________________________________
  1347. X
  1348. X
  1349. XSo, a class of objects called MY-TOOLS was created.  Note that the class
  1350. Xobject  MY-TOOLS was created by sending the :NEW message to the built-in
  1351. XCLASS  object.  Within  the  MY-TOOL  class,  there are three  instances
  1352. Xcalled DRILL, HAND-SAW and TABLE-SAW.  These were created by sending the
  1353. X:NEW message to the MY-TOOLS  class object.  Notice that the  parameters
  1354. Xfollowed the message selector.
  1355. X
  1356. X
  1357. XINSTANCES
  1358. X
  1359. XThe  following  is a display of the  contents of some of the  previously
  1360. Xcreated instances:
  1361. X
  1362. X     ________________________________________________________________
  1363. X    |
  1364. X    |    > (send drill :show)
  1365. X    |    Object is #<Object: #2ddbc>, Class is #<Object: #277a6>
  1366. X    |      POWER = AC
  1367. X    |      MOVEABLE = T
  1368. X    |      OPERATION = HOLES
  1369. X    |    #<Object: #2ddbc>
  1370. X    |
  1371. X    |    > (send hand-saw :show)
  1372. X    |    Object is #<Object: #2dc40>, Class is #<Object: #277a6>
  1373. X    |      POWER = NONE
  1374. X    |      MOVEABLE = T
  1375. X    |      OPERATION = CUTS
  1376. X    |    #<Object: #2dc40>
  1377. X    |________________________________________________________________
  1378. X
  1379. X
  1380. XFrom  the  display  of  these  instances  you  can see  there  are  some
  1381. Xcomponents and values.  The components of an instance are:
  1382. X
  1383. X    Class Pointer           This  pointer  shows to which  class the
  1384. X                current object instance  belongs.  It is
  1385. X                through this link that the system  finds
  1386. X                the methods to execute for the  received
  1387. X                messages.
  1388. X
  1389. X    Instance Variables      The Instance  Variables (IVAR) component
  1390. X    and Values        lists what  variables  exist  within the
  1391. X                instance.  The Instance Values component
  1392. X                holds  what the  current  values  of the
  1393. X                variables  are.  Instance  Variables are
  1394. X                used to hold state  information for each
  1395. X                instance.  There  will  be  a  group  of
  1396. X                Instance Variables for each instance.
  1397. X
  1398. X
  1399. X
  1400. X
  1401. XMETHODS
  1402. X
  1403. XThere have been a few of the messages and methods in XLISP shown to this
  1404. Xpoint (:NEW and :SHOW).  The following are the methods built into XLISP:
  1405. X
  1406. X    :ANSWER         The  :ANSWER  method  allows  you to  define  or
  1407. X            change methods within a class.
  1408. X
  1409. X    :CLASS         The :CLASS method returns the class of an object.
  1410. X
  1411. X    :ISNEW          The :ISNEW method  causes an instance to run its
  1412. X            initialization  code.  When the :ISNEW method is
  1413. X            run on a class, it resets the class state.  This
  1414. X            allows  you  to  re-define  instance  variables,
  1415. X            class variables, etc.
  1416. X
  1417. X    :NEW            The :NEW method allows you to create an instance
  1418. X            when the :NEW message is sent to a  user-defined
  1419. X            class.  The :NEW  method  allows you to create a
  1420. X            new class (when the :NEW  message is sent to the
  1421. X            built-in CLASS).
  1422. X
  1423. X    :SHOW         The :SHOW method displays the instance or class.
  1424. X
  1425. X
  1426. X
  1427. XSENDING MESSAGES TO A SUPERCLASS
  1428. X
  1429. XIn  addition  to the SEND  function,  there is another  function  called
  1430. XSEND-SUPER.  The SEND-SUPER  function causes the specified message to be
  1431. Xperformed  by the  superclass  method.  This  is a  mechanism  to  allow
  1432. Xchaining of methods in a class hierarchy.  This chaining behavior can be
  1433. Xachieved  by  creating a method  for a class with the  :ANSWER  message.
  1434. XWithin the body of the  method,  you  include a  SEND-SUPER  form.  This
  1435. Xfunction is allowed only inside the  execution of a method of an object.
  1436. X
  1437. X
  1438. XOBJECT AND CLASS
  1439. X
  1440. XThe definition of the built-in class OBJECT is:
  1441. X
  1442. X     ________________________________________________________________
  1443. X    |
  1444. X    |    > (send object :show)
  1445. X    |    Object is #<Object: #23fd8>, Class is #<Object: #23fe2>
  1446. X    |      MESSAGES = ((:SHOW . #<Subr-: #23db2>) 
  1447. X    |                (:CLASS . #<Subr-: #23dee>) 
  1448. X    |              (:ISNEW . #<Subr-: #23e2a>))
  1449. X    |      IVARS = NIL
  1450. X    |      CVARS = NIL
  1451. X    |      CVALS = NIL
  1452. X    |      SUPERCLASS = NIL
  1453. X    |      IVARCNT = 0
  1454. X    |      IVARTOTAL = 0
  1455. X    |    #<Object: #23fd8>
  1456. X    |________________________________________________________________
  1457. X
  1458. X
  1459. XNote that OBJECT is a class - as opposed to an "instance-style"  object.
  1460. XOBJECT has no superclass, it is the top or root of the class  hierarchy.
  1461. XOBJECT's class is CLASS.
  1462. X
  1463. X     ________________________________________________________________
  1464. X    |
  1465. X    |    > (send class :show)
  1466. X    |    Object is #<Object: #23fe2>, Class is #<Object: #23fe2>
  1467. X    |      MESSAGES = ((:ANSWER . #<Subr-: #23e48>) 
  1468. X    |                (:ISNEW . #<Subr-: #23e84>) 
  1469. X    |              (:NEW . #<Subr-: #23ea2>))
  1470. X    |      IVARS = (MESSAGES IVARS CVARS CVALS SUPERCLASS 
  1471. X    |           IVARCNT IVARTOTAL)
  1472. X    |      CVARS = NIL
  1473. X    |      CVALS = NIL
  1474. X    |      SUPERCLASS = #<Object: #23fd8>
  1475. X    |      IVARCNT = 7
  1476. X    |      IVARTOTAL = 7
  1477. X    |    #<Object: #23fe2>
  1478. X    |________________________________________________________________
  1479. X
  1480. X
  1481. XCLASS has a superclass of OBJECT.  It's class is itself - CLASS. 
  1482. X
  1483. X
  1484. X
  1485. X
  1486. SHAR_EOF
  1487. if test 15230 -ne "`wc -c 'xlisp.txt'`"
  1488. then
  1489.     echo shar: error transmitting "'xlisp.txt'" '(should have been 15230 characters)'
  1490. fi
  1491. #    End of shell archive
  1492. exit 0
  1493. -- 
  1494. Gary Murphy                   uunet!mitel!sce!cognos!garym
  1495.                               (garym%cognos.uucp@uunet.uu.net)
  1496. (613) 738-1338 x5537          Cognos Inc. P.O. Box 9707 Ottawa K1G 3N3
  1497. "There are many things which do not concern the process" - Joan of Arc
  1498.  
  1499.